const app = getApp();
import QQMapWX from '../../libs/qqmap-wx-jssdk.min.js';

var qqmapsdk;

Page({
  data: {
    // 后勤通知
    noticeShow: false,
    noticeTitle: '',
    noticeContent: '',
    noticeDate: '',
    modalName: null,

    degree: '',
    weather: '',
    tips: '',
    festivalTips: null,
    province: null,
    city: '',
    cardCur: 0,
    swiperList: [{
      id: 1,
      type: 'image',
      url: 'https://6a69-jiangnan-4geqm4p05de994f4-1306258930.tcb.qcloud.la/login.png?sign=5eb91871eab380333453e5749e66a922&t=1624196855',
    }, {
      id: 2,
      type: 'image',
      url: 'https://6a69-jiangnan-4geqm4p05de994f4-1306258930.tcb.qcloud.la/back.jpg?sign=aa57b76d6f238a6f48d4197b57d29e97&t=1624196819',
    }, {
      id: 3,
      type: 'image',
      url: 'https://6a69-jiangnan-4geqm4p05de994f4-1306258930.tcb.qcloud.la/swiper3.jpg?sign=13909379f5d8de8a564799077e1e2d8b&t=1624196788',
    },
  {
    id: 3,
      type: 'image',
      url: 'https://6a69-jiangnan-4geqm4p05de994f4-1306258930.tcb.qcloud.la/swiper1.jpg?sign=32de0dc0c3fab9d85576f7c2fa0db581&t=1624196744',
  }],
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    iconList: [{
      id: 0,
      icon: 'read',
      color: 'red',
      badge: 0,
      name: '成绩查询',
      navUrl: '../navigation/old/query/score/score'
    }, {
      id: 1,
      icon: 'news',
      color: 'orange',
      badge: 0,
      name: '学分查询',
      navUrl: '../navigation/old/query/credit/credit'
    }, {
      id: 2,
      icon: 'searchlist',
      color: 'yellow',
      badge: 0,
      name: '课程表'
    }, {
      id: 3,
      icon: 'repair',
      color: 'olive',
      badge: 0,
      name: '失物招领'
    }, {
      id: 4,
      icon: 'activity',
      color: 'cyan',
      badge: 0,
      name: '校历',
      navUrl: './calendar/calendar'
    }, {
      id: 5,
      icon: 'time',
      color: 'mauve',
      badge: 0,
      name: '就业信息',
      navUrl:'../navigation/old/work/work'
    }, {
      id: 6,
      icon: 'calendar',
      color: 'pink',
      badge: 0,
      name: '专业资源',
      navUrl: '../navigation/old/wealth/wealth'
    }, {
      id: 7,
      icon: 'group',
      color: 'purple',
      badge: 0, 
      name: '地图导航',
      navUrl: '../navigation/new/map/map'
    }],
    gridCol: 3,
    skin: false,
    weekday:'星期一',
    nthWeek:'第十六周',
    num:2,
    todayCourses: [
      {
        nthCourse:'01 | 02',
        courseName:'软件需求分析',
        location:'松2334',
        courseTime:'08:15-9:15'
      },
      {
        nthCourse:'03 | 04',
        courseName:'软件前沿技术',
        location:'松2334',
        courseTime:'10:05-11:35'
      }
    ]
  },

  /**
   * 点击九宫格
   */
  bindGrid: function (e) {
    if (e.currentTarget.dataset.id == 2||e.currentTarget.dataset.id == 3) {
      wx.showToast({
        title: '未完成的功能',
        icon: 'none',
        duration: 2000
      })
    }
  },
  onLoad() {
    this.towerSwiper('swiperList');
    // 初始化towerSwiper 传已有的数组名即可
    wx.showShareMenu({
      withShareTicket: true
    })
  },
  DotStyle(e) {
    this.setData({
      DotStyle: e.detail.value
    })
  },
  // cardSwiper
  cardSwiper(e) {
    this.setData({
      cardCur: e.detail.current
    })
  },
  // towerSwiper
  // 初始化towerSwiper
  towerSwiper(name) {
    let list = this.data[name];
    for (let i = 0; i < list.length; i++) {
      list[i].zIndex = parseInt(list.length / 2) + 1 - Math.abs(i - parseInt(list.length / 2))
      list[i].mLeft = i - parseInt(list.length / 2)
    }
    this.setData({
      swiperList: list
    })
  },
  // towerSwiper触摸开始
  towerStart(e) {
    this.setData({
      towerStart: e.touches[0].pageX
    })
  },
  // towerSwiper计算方向
  towerMove(e) {
    this.setData({
      direction: e.touches[0].pageX - this.data.towerStart > 0 ? 'right' : 'left'
    })
  },
  // towerSwiper计算滚动
  towerEnd(e) {
    let direction = this.data.direction;
    let list = this.data.swiperList;
    if (direction == 'right') {
      let mLeft = list[0].mLeft;
      let zIndex = list[0].zIndex;
      for (let i = 1; i < list.length; i++) {
        list[i - 1].mLeft = list[i].mLeft
        list[i - 1].zIndex = list[i].zIndex
      }
      list[list.length - 1].mLeft = mLeft;
      list[list.length - 1].zIndex = zIndex;
      this.setData({
        swiperList: list
      })
    } else {
      let mLeft = list[list.length - 1].mLeft;
      let zIndex = list[list.length - 1].zIndex;
      for (let i = list.length - 1; i > 0; i--) {
        list[i].mLeft = list[i - 1].mLeft
        list[i].zIndex = list[i - 1].zIndex
      }
      list[0].mLeft = mLeft;
      list[0].zIndex = zIndex;
      this.setData({
        swiperList: list
      })
    }
  },
  onShow() {
    var that = this;
    this.getTabBar().init();
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (ops) {
    return {
      title: '我发现一个很有用的校园小程序，推荐给你~',
      path: 'pages/index/index', // 路径，传递参数到指定页面。
      success: function (res) { },
      fail: function (res) { }
    }
  }
})